// 创建路由对象
import { createRouter, createWebHashHistory } from 'vue-router'

// 配置路由规则
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      component: () => import('@/views/Layout/Layout.vue'),
      children: [
        {
          path: 'playground',
          component: () => import('@/views/Playground/Playground.vue')
        },
        {
          // 首页路由, 默认路由
          path: '',
          component: () => import('@/views/Home/Home.vue')
        },
        {
          path: 'category/:id',
          component: () => import('@/views/Category/Category.vue')
        },
        {
          path: 'goods/:id',
          component: () => import('@/views/Goods/Goods.vue')
        }
      ]
    },
    {
      path: '/login',
      // 路由懒加载
      component: () => import('@/views/Login/Login.vue')
    }
  ],
  // 切换路由时自动滚动到顶部
  scrollBehavior: () => {
    return {
      top: 0,
    }
  }
})

// 导出路由对象
export default router